import type { MesProcess, MesProcessStep } from "@/pages/mes/process/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //工序编码
  processCode?: string;
  //工序名称
  processName?: string;
  //是否启用
  enableFlag?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: MesProcess[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/mes/process/pageList",
    data
});

const list = (): Promise<MesProcess[]> =>
  apiClient.get({
    url: "/mes/process/list",
});

const getInfo = (id: React.Key): Promise<MesProcess> =>
  apiClient.get({
    url: `/mes/process/${id}`
});

const add = (data: MesProcess): Promise<MesProcess> =>
  apiClient.post({
    url: "/mes/process",
    data
});

const update = (data: MesProcess): Promise<MesProcess> =>
  apiClient.put({
    url: "/mes/process",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/mes/process",
    params: {
    ids: ids.join(",")
  }
});
const getsteps = (id: React.Key): Promise<MesProcessStep[]> =>
  apiClient.post({
    url: "/mes/process/step/list",
    data: {
      processId: id
    }
  });

export const mesProcessService = {
  pageList,
  list,
  getInfo,
  add,
  update,
  remove,
  getsteps,
};

export default mesProcessService;